Skip to content

fix: add structured exit codes for different failure categories (#11)#14

Open
aidandaly24 wants to merge 8 commits intomainfrom
loopy/issue-11
Open

fix: add structured exit codes for different failure categories (#11)#14
aidandaly24 wants to merge 8 commits intomainfrom
loopy/issue-11

Conversation

@aidandaly24
Copy link
Copy Markdown
Owner

Summary

Adds structured exit codes for different failure categories, enabling programmatic distinction between failure types in CI/CD pipelines and wrapper scripts.

Closes #11

Changes

New: src/cli/exit-codes.ts

  • Exports ExitCode const object with 7 named exit codes (0-6)
  • Exports ExitCodeValue type for type-safe usage
  • Exports getExitCode(err: unknown): number function that maps errors to the correct exit code
Exit Code Constant Meaning
0 SUCCESS Command succeeded
1 GENERAL_ERROR Unknown/unhandled error
2 INVALID_ARGS Invalid CLI arguments or missing required flags
3 AUTH_EXPIRED AWS credentials expired or invalid
4 ACCESS_DENIED IAM permission error
5 AGENT_NOT_FOUND Requested agent doesn't exist
6 DEPLOY_FAILED Deployment/CloudFormation failure

The getExitCode() function checks errors in priority order:

  1. isAccessDeniedError()ACCESS_DENIED (4)
  2. isExpiredTokenError()AUTH_EXPIRED (3)
  3. isNoCredentialsError()AUTH_EXPIRED (3)
  4. Commander invalid argument errors → INVALID_ARGS (2)
  5. isStackInProgressError() / isChangesetInProgressError()DEPLOY_FAILED (6)
  6. Agent not found message patterns → AGENT_NOT_FOUND (5)
  7. Default → GENERAL_ERROR (1)

Modified: src/cli/index.ts

  • Added import for getExitCode from ./exit-codes.js
  • Replaced all 3 hardcoded process.exit(1) calls with process.exit(getExitCode(err))
  • Backward compatible: unknown errors still exit with code 1

New: src/cli/__tests__/exit-codes.test.ts

  • Comprehensive unit tests covering all exit code mappings
  • Tests for access denied, expired tokens, no credentials, commander errors, deploy failures, agent not found, and default general error
  • Priority ordering tests to verify correct classification when errors could match multiple categories

Acceptance Criteria

  • Exit codes enum/object exported from new file
  • getExitCode() correctly maps isAccessDeniedError()EXIT_ACCESS_DENIED
  • getExitCode() correctly maps expired token errors → EXIT_AUTH_EXPIRED
  • Top-level error handler uses getExitCode() instead of hardcoded 1
  • Unit tests cover all exit code mappings
  • Unknown errors default to EXIT_GENERAL_ERROR (1)

Create src/cli/exit-codes.ts with ExitCode constants and getExitCode()
mapping function that classifies errors into specific exit codes.
Replace hardcoded process.exit(1) calls with process.exit(getExitCode(err))
in all 3 error handlers in src/cli/index.ts.
Cover all exit code mappings including access denied, expired tokens,
no credentials, commander errors, deploy failures, agent not found,
default general error, and priority ordering.
@github-actions github-actions Bot added the size/m PR size: M label Mar 19, 2026
@aidandaly24 aidandaly24 changed the title fix: Add structured exit codes for different failure categories (#11) fix: add structured exit codes for different failure categories Mar 19, 2026
@aidandaly24 aidandaly24 changed the title fix: add structured exit codes for different failure categories fix: add structured exit codes for different failure categories (#11) Mar 19, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 19, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 43.21% 4931 / 11410
🔵 Statements 42.81% 5221 / 12194
🔵 Functions 42.51% 903 / 2124
🔵 Branches 44.79% 3204 / 7153
Generated in workflow #49 for commit 7d66a74 by the Vitest Coverage Report Action

Use direct property casts instead of Record<string, unknown> index
access to avoid noUncheckedIndexedAccess issues with constructor.name.
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Mar 19, 2026
Cast to a specific interface instead of Record<string, unknown> to
ensure type-safe property access for code, exitCode, and constructor.
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Mar 19, 2026
)

Use specific type assertions instead of Record<string, unknown> to avoid
noUncheckedIndexedAccess issues with constructor property access.
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Mar 19, 2026
Use Object.assign instead of type assertion for adding properties to
Error objects. Reformat to match prettier output.
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Mar 19, 2026
…code (#11)

- Add ResourceNotFoundException error name check to isAgentNotFoundError()
  to match the AWS SDK error pattern used throughout the codebase
- Add test for ResourceNotFoundException mapping to AGENT_NOT_FOUND (5)
- Add test for agent not found in deployed state message pattern
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Mar 20, 2026
@github-actions
Copy link
Copy Markdown

Package Tarball

aws-agentcore-0.3.0-preview.6.0.tgz

How to install

npm install https://github.com/aidandaly24/agentcore-cli/releases/download/pr-14-tarball/aws-agentcore-0.3.0-preview.6.0.tgz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add structured exit codes for different failure categories

1 participant